//
//  ZDBSetViewController.m
//  ZDB
//
//  Created by Kk on 2020/3/17.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBSetViewController.h"
#import "ZDBSettingTableViewCell.h"
@interface ZDBSetViewController ()
<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)NSMutableArray *dataSource;
@property (nonatomic, strong) UITableView * tableView;
@end

@implementation ZDBSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSource = [NSMutableArray array];
    // Do any additional setup after loading the view from its nib.
    
    [self creat_UI];
    [self step_Data];
    
    
}
-(void)creat_UI{
    
    [self.view addSubview:self.tableView];
    UIView * topView = [BBControl createViewWithFrame:CGRectMake(0, 0, kScreenWidth, 5)];
    topView.backgroundColor = [UIColor clearColor];
    self.tableView.tableHeaderView = topView;
    UIView * bottomView = [BBControl createViewWithFrame:CGRectMake(0, 0, kScreenWidth, 90)];
    bottomView.backgroundColor = [UIColor clearColor];
    UIButton * logoutBtn = [BBControl createButtonWithFrame:CGRectMake(0, 40, kScreenWidth, 50) target:self SEL:@selector(logoutBtnClick) title:@"退出登录"];
    [bottomView addSubview:logoutBtn];
    [logoutBtn setTitleColor:[UIColor whiteColor] forState:0];
    [logoutBtn setBackgroundColor:MAINCOLOR forState:0];
    self.tableView.tableFooterView = bottomView;
    
}
-(void)logoutBtnClick{
    
    [[DJLoginHelper sharedInstance] loginOut];
    if (self.logoutClickBlock) {
        self.logoutClickBlock(YES);
    }
    [self.navigationController popViewControllerAnimated:YES];
    
}
-(void)step_Data{
    
    self.dataSource = @[
        @{
            @"type":@(1),
            @"title":@"联系我们"
        },
        @{
                   @"type":@(1),
                   @"title":@"意见反馈"
               },
        @{
                   @"type":@(1),
                   @"title":@"隐私协议"
               },
        @{
                   @"type":@(1),
                   @"title":@"关于我们"
               },
        @{
                   @"type":@(2),
                   @"title":@"检查更新"
               }

    ].mutableCopy;
    
    [self.tableView reloadData];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZDBSettingTableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"ZDBSettingTableViewCell" forIndexPath:indexPath];
   cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row ==4) {
        cell.subLab.text = [NSString stringWithFormat:@"当前版本%@",kAppVersion];
    }
    cell.dataDicc = self.dataSource[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma  mark -----懒加载
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, UIScreenHeight  - kStatusBarAndNavigationBarHeight)style:UITableViewStylePlain];
        _tableView.tableFooterView = [UIView new];
        _tableView.separatorColor = CELLCOLOR;
        _tableView.delegate = self;
        _tableView.dataSource=self;
        _tableView.sectionHeaderHeight = 0.01;
        _tableView.sectionFooterHeight = 0.01;
        _tableView.backgroundColor =  VIEWBGCOLOR;
        _tableView.showsVerticalScrollIndicator = NO;
        [_tableView registerNib:[UINib nibWithNibName:@"ZDBSettingTableViewCell" bundle:nil]  forCellReuseIdentifier:@"ZDBSettingTableViewCell"];
    
    }
    return _tableView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
